/*
 *copyright (C) 2015-2018 Alibaba Group Holding Limited
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include <aos/aos.h>
#include <aos/yloop.h>
#include "iot_export.h"
#include "iot_import.h"
#include "smart_outlet.h"

#ifdef REPORP_ON_DEMAND
#define REPORT_TIMEOUT_MS   (1 * 30 * 1000)
static aos_timer_t report_timeout_timer;

extern int set_report_state(int enable);
extern void user_post_all_property(void);
static void report_setting_handler(void *arg1, void *arg2);

int init_report_service(void)
{
    /* scan wifi */
    int ret = 0;
    aos_timer_new_ext(&report_timeout_timer, report_setting_handler, NULL, REPORT_TIMEOUT_MS, 0, 0);

    return ret;
}

int deinit_report_service(void)
{
    /* scan wifi */
    int ret = 0;
    aos_timer_free(&report_timeout_timer);
    return ret;
}

static void report_setting_handler(void *arg1, void *arg2)
{
    app_info("report timeout, stop report");
    set_report_state(0);
    aos_timer_stop(&report_timeout_timer);
}

int start_report_on_demand(void)
{
    app_info("start report");
    aos_timer_stop(&report_timeout_timer);
    aos_timer_start(&report_timeout_timer);
    set_report_state(1);
    user_post_all_property();
}
#endif
